package com.sf.sms.utils;

import java.io.IOException;
import java.net.URL;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.sql.SQLException;

import javax.xml.parsers.ParserConfigurationException;

import org.xml.sax.SAXException;

import com.sf.sms.utils.AutoConstructionUtil;

/**
 * 根据已创建的以wp_起始的数据表，自动构建出相应的model、mapper、service、controller文件，
 * 并默认构建一个保存函数
 *
 */
public class AutoConstruction {
	public static void main(String args[]) {
		try {
			String packageName = AutoConstruction.class.getPackage().getName();
			ProtectionDomain domain = AutoConstruction.class.getProtectionDomain();
			CodeSource codeSource = domain.getCodeSource();
			URL location = codeSource.getLocation();
			String path = location.getPath();
			System.out.println(path);
			path = path.substring(0, path.indexOf("bin"));
			path = path.substring(1);
			System.out.println(packageName);
			String javaFilePath = path + "src/main/java/" + packageName.replaceAll("\\.", "/").replace("utils", "");
			javaFilePath = javaFilePath.replaceAll("/", "\\\\");
			System.out.println(javaFilePath);
			AutoConstructionUtil acu = new AutoConstructionUtil();
			acu.autoGenerateByTableName(javaFilePath, packageName.replace(".utils", ""));
		} catch (ClassNotFoundException | ParserConfigurationException | SAXException | IOException | SQLException e) {
			e.printStackTrace();
		}
	}
}
